Imports System.Windows.Forms
Imports Snowball.Actions.ActionParameter
Imports Snowball.Actions

Public Class frmSettings

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Config.CurrentConfig.ReportDefinitionsFileName = txtDefinitionsFile.Text
        Config.CurrentConfig.WorkingDirectory = txtSnowballProcessFolder.Text
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each parKey As String In Config.CurrentConfig.GlobalParameters.Keys
            lstGlobals.Items.Add(parKey)
        Next
        If lstGlobals.Items.Count > 0 Then lstGlobals.SetSelected(lstGlobals.TopIndex, True)

        txtSnowballProcessFolder.Text = Config.CurrentConfig.WorkingDirectory
        txtDefinitionsFile.Text = Config.CurrentConfig.ReportDefinitionsFileName
    End Sub

    Private Sub lstGlobals_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstGlobals.SelectedIndexChanged
        Dim parKey As String = lstGlobals.SelectedItem.ToString
        With Config.CurrentConfig.GlobalParameters
            If .ContainsKey(parKey) Then
                Dim par As ActionParameter = .Item(parKey)
                lblParCode.Text = par.Name
                txtParameterValue.Text = par.Value.ToString
                If par.Type = TypeEnum.tpPassword Then
                    txtParameterValue.UseSystemPasswordChar = True
                    txtParameterValue.Multiline = False
                Else
                    txtParameterValue.UseSystemPasswordChar = False
                    txtParameterValue.Multiline = True

                End If
            End If
        End With
    End Sub

    Private Sub txtParameterValue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtParameterValue.TextChanged
        Dim parKey As String = lstGlobals.SelectedItem.ToString
        With Config.CurrentConfig.GlobalParameters
            If .ContainsKey(parKey) Then
                .Item(parKey).Value = txtParameterValue.Text
            End If
        End With
    End Sub

    Private Sub cmdReloadReportDefinitions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReloadReportDefinitions.Click
        frmSnowBall.MainForm.ReloadAvailableProcesses()
    End Sub

End Class
